package org.mosquitos.chat;

import java.net.URISyntaxException;
import java.net.URI;

import net.jxta.document.AdvertisementFactory;
import net.jxta.id.IDFactory;
import net.jxta.peergroup.PeerGroup;
import net.jxta.pipe.PipeID;
import net.jxta.protocol.PipeAdvertisement;

public class AdvertisementCreator {
	
    public static PipeAdvertisement createAdv(PeerGroup peerGroup, String name, String type, String pipeId) {
    	PipeAdvertisement pa = (PipeAdvertisement) AdvertisementFactory.newAdvertisement(PipeAdvertisement.getAdvertisementType());

    	try {
			pa.setPipeID(pipeId == null?IDFactory.newPipeID(peerGroup.getPeerGroupID()):(PipeID) IDFactory.fromURI(new URI(pipeId)));
	    	pa.setName(name);
	    	pa.setType(type);
		} catch (URISyntaxException e) {
			e.printStackTrace();
		}
		peerGroup.getDiscoveryService().remotePublish(pa);
		
    	return pa;
    }

}
